package com.ruoyi.app.framework.manager.factory;

import com.ruoyi.app.controller.common.service.impl.ApiAsyncActivityServiceImpl;
import com.ruoyi.app.controller.common.service.impl.ApiAsyncNotifyServiceImpl;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.TimerTask;

/**
 * 异步工厂（产生任务用）
 *
 * @author liuhulu
 */
public class ApiAsyncFactory {
    private static final Logger api_sync_log = LoggerFactory.getLogger("api-sync");

    /**
     * 微信模板通知
     *
     * @return
     */
    public static TimerTask sendWechatTemplateNotify(HashMap<String, String> params) {
        return new TimerTask() {
            @Override
            public void run() {
                SpringUtils.getBean(ApiAsyncNotifyServiceImpl.class).sendWechatTemplateNotify(params);
            }
        };
    }

    /**
     * 播报通知
     *
     * @return
     */
    public static TimerTask sendAnnounceNotify(HashMap<String, String> params) {
        return new TimerTask() {
            @Override
            public void run() {
                SpringUtils.getBean(ApiAsyncNotifyServiceImpl.class).sendAnnounceNotify(params);
            }
        };
    }

    /**
     * 短信通知
     *
     * @return
     */
    public static TimerTask sendSmsNotify(HashMap<String, String> params) {
        return new TimerTask() {
            @Override
            public void run() {
                SpringUtils.getBean(ApiAsyncNotifyServiceImpl.class).sendSmsNotify(params);
            }
        };
    }

    /**
     * 刷新优惠券
     *
     * @return
     */
    public static TimerTask refreshCoupon(String couponIdStr) {
        return new TimerTask() {
            @Override
            public void run() {
                HttpUtils.sendGet("http://127.0.0.1:5001/back/crontab/refreshCoupon/"+couponIdStr);
            }
        };
    }

    /**
     * 注册赠送优惠券
     *
     * @return
     */
    public static TimerTask registerSendCoupon(Long memberId,Long shopId) {
        return new TimerTask() {
            @Override
            public void run() {
                SpringUtils.getBean(ApiAsyncActivityServiceImpl.class).registerSendCoupon(memberId,shopId);
            }
        };
    }


}
